import { createMogodb, MongoDBClient } from '../db';
import { FreeWorld } from './free-proxy-world';
import { ETLClient, ExtractClientInterface, LoadClient, MultiExtractClient, ProxyInterface, TransformerPipeline, TransformMessage, TransformProtocol, TransformRTT, UpdateExtract } from '../etl';
import { FreeProxy } from './free-proxy';
import { GithubProxy } from './github-proxy';
import { ProxyListsImpl } from './proxy-lists';
import { getLogger } from '../utils/log4j';
import axios from 'axios';


const logger = getLogger(`proxy-serve`)
export async function proxyServe(config: any, client: MongoDBClient<ProxyInterface>, childClient: MongoDBClient<ProxyInterface>) {

    try {
        const { axioss, proxyResourceUrls } = config
        const { rttAxios, protocolAxios } = axioss
        //Extract
        const freeProxy = new FreeProxy()
        const freeWorld = new FreeWorld()
        const github = new GithubProxy(proxyResourceUrls)
        const proxyLists = new ProxyListsImpl()
        const extractArr: ExtractClientInterface[] = [freeProxy, freeWorld, github, proxyLists]
        const multiExtract = new MultiExtractClient(extractArr)

        //transform
        const rttTransform = new TransformRTT()
        const messageTransform = new TransformMessage()
        const protocolTransform = new TransformProtocol()
        const transformArr = [rttTransform, messageTransform, protocolTransform]
        const transformPipeline = new TransformerPipeline(transformArr)

        const load = new LoadClient(client)
        // const etl = new ETLClient(multiExtract, transformPipeline, load)
        // await etl.etl()

    } catch (error) {
        logger.error(`proxy-serve proxyServe error ${error}`)
    }

}

export async function updateProxy(config: any, client: MongoDBClient<ProxyInterface>) {
    const { rttAxios, protocolAxios } = config

    // try {
    //     const update = new UpdateExtract(client)
    //     let transofrm = new TransformerClient(rttAxios, protocolAxios)
    //     const load = new LoadClient(client)
    //     const etl = new ETLClient(update, transofrm, load)
    //     etl.etl()
    // } catch (error) {
    //     logger.error(`updateProxy start error ${error}`)
    // }


}

